package com.elastic.sort.impl;

import com.elastic.sort.BuilderType;
import com.elastic.sort.type.BaseEnumType;
import com.elastic.sort.type.DefaultEnumType;
import org.elasticsearch.search.sort.SortBuilder;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;

/**
 * @ClassName DefaultBuilderType
 * @Author xiezhuocai
 * @Description 实现默认排序,按综合评分排序
 * @Date 2021/12/22 11:46
 */
public class DefaultBuilderType implements BuilderType {

    @Override
    public SortBuilder<?> setSort(BaseEnumType sortType) {
        SortBuilder<?> sortBuilder;
        DefaultEnumType defaultEnumType = (DefaultEnumType)sortType;
        switch (defaultEnumType) {
            case DEFAULT:
                sortBuilder = SortBuilders.scoreSort().order(SortOrder.DESC);
                break;
            default:
                throw new RuntimeException("排序类型错误");
        }
        return sortBuilder;
    }

}
